/*
 This file is part of TEdit
 Copyright (C) 2009 Team16
 Writed by Bonapart(aka Justuser)
All modification should link to me or my page as program creator
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. This program is distributed in the
hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License
for more details. You should have received a copy of the GNU General
Public License along with this program. If not, see <http://www.gnu.org/license>
 */
#include "options.h"

options::options(QWidget *parent) :
    QDialog(parent)
{
    QVBoxLayout *lay=new QVBoxLayout(this);
    QGroupBox *mn=new QGroupBox(tr("Меню"),this);
    QGroupBox *ed=new QGroupBox(tr("Редактор"),this);
    lay->addWidget(ed);
    lay->addWidget(mn);
    QVBoxLayout *lay2=new QVBoxLayout(mn);
    QVBoxLayout *lay3=new QVBoxLayout(ed);

    mnSize=new QSpinBox(this);
    edSize=new QSpinBox(this);
    kdSize=new QSpinBox(this);
    mnFont=new QFontComboBox(this);
    edFont=new QFontComboBox(this);

    lay2->addWidget(mnSize);
    lay2->addWidget(mnFont);

    lay3->addWidget(edSize);
    lay3->addWidget(edFont);

    mnSize->setMinimum(6);
    edSize->setMinimum(6);

    mnSize->setMaximum(20);
    edSize->setMaximum(20);

    kdSize->setMinimum(6);
    kdSize->setMaximum(20);
lay->addWidget(kdSize);

QPushButton *save=new QPushButton(tr("Сохранить"),this);
QPushButton *canc=new QPushButton(tr("Отмена"),this);


QFile u("/data/tedit/opt.txt");
 if (!u.open(QIODevice::ReadOnly | QIODevice::Text))return;
QTextStream t(&u);
msize=t.readLine().toInt();
esize=t.readLine().toInt();
mfont=t.readLine();
efont=t.readLine();
ksize=t.readLine().toInt();
u.close();

lay->addWidget(save);
lay->addWidget(canc);
connect(save,SIGNAL(clicked()),this,SLOT(sv()));
connect(canc,SIGNAL(clicked()),this,SLOT(cn()));

mnSize->setValue(msize);
edSize->setValue(esize);
kdSize->setValue(ksize);
QFont font;
font.fromString(mfont);
mnFont->setFont(font);
font.fromString(efont);
edFont->setFont(font);
}


void options::cn(){
    this->reject();
}

void options::sv(){
    QFile u("/data/tedit/opt.txt");
    if (!u.open(QIODevice::WriteOnly | QIODevice::Text))return;
    QTextStream t(&u);
    msize=mnSize->value();
    esize=edSize->value();
    mfont=mnFont->currentFont().toString();
    efont=edFont->currentFont().toString();
    ksize=kdSize->value();
    QString txt=QString("%1\n%2\n%3\n%4\n\%5").arg(msize).arg(esize).arg(mfont).arg(efont).arg(ksize);
    t<<txt;
    u.close();
    this->accept();
}
